package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.common.utils.DateUtils;
import com.atguigu.dao.TravelSetmealDao;
import com.atguigu.pojo.Member;
import com.atguigu.service.MemberService;
import com.atguigu.service.OrderInfoService;
import com.atguigu.service.ReportService;
import com.atguigu.vo.BusinessReportDataVo;
import com.atguigu.vo.HotSetmealVo;
import com.atguigu.vo.SetmealNameVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    MemberService memberService;
    @Autowired
    TravelSetmealDao travelSetmealDao;
    @Autowired
    OrderInfoService orderInfoService;

    @Override
    public List<Integer> getMemberMonth(ArrayList<String> list) {
        return memberService.getMemberMonth(list);
    }

    @Override
    public List<SetmealNameVo> findSetmealAndOrder() {
        return travelSetmealDao.findSetmealAndOrder();
    }

    @Override
    public BusinessReportDataVo getBusinessReportData() {
        BusinessReportDataVo dataVo = new BusinessReportDataVo();
        //获取当前日期 并格式化
        String format = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        dataVo.setReportDate(format);
        // 新增会员数 查询当天会员数
        Integer todayNewMember = memberService.selectDate(format);
        dataVo.setTodayNewMember(todayNewMember);
        // 总会员数 查询所有member
        Integer totalMember = memberService.selectAll();
        dataVo.setTotalMember(totalMember);
        // 本周新增会员数 查询一周内增加的会员数
        //获取本周一是几号
        Date weekMonday = DateUtils.getThisWeekMonday();
        //获取本周的最后一天
        Date lastDay = DateUtils.getSundayOfThisWeek();
        //查询一周内增加的会员数
        Integer thisWeekNewMember = memberService.selectWeek(weekMonday,lastDay);
        dataVo.setThisWeekNewMember(thisWeekNewMember);
        // 本月新增会员数 查询一个月内增加的会员数
        String dateString = new SimpleDateFormat("yyyy-MM").format(new Date());
        Integer thisMonthNewMember = memberService.selectMonth(dateString);
        dataVo.setThisMonthNewMember(thisMonthNewMember);
        // 今日预约数 查询今日的预约数 count
        Integer todayOrderNumber = orderInfoService.selectOrderType(new Date());
        dataVo.setTodayOrderNumber(todayOrderNumber);
        // 今日出游数 查询今日的出游数
        Integer todayVisitsNumber = orderInfoService.selectTodayVisitsNumber(new Date());
        dataVo.setTodayVisitsNumber(todayVisitsNumber);
        // 本周预约数 查询本周的预约数
        Integer thisWeekOrderNumber = orderInfoService.selectThisWeekOrderNumber(weekMonday,lastDay);
        dataVo.setThisWeekOrderNumber(thisWeekOrderNumber);
        // 本周出游数
        Integer thisWeekVisitsNumber = orderInfoService.selectThisWeekVisitsNumber(weekMonday,lastDay);
        dataVo.setThisWeekVisitsNumber(thisWeekVisitsNumber);
        // 本月预约数
        Integer thisMonthOrderNumber = orderInfoService.selectThisMonthOrderNumber(dateString);
        dataVo.setThisMonthOrderNumber(thisMonthOrderNumber);
        // 本月出游数
        Integer thisMonthVisitsNumber = orderInfoService.selectThisMonthVisitsNumber(dateString);
        dataVo.setThisMonthVisitsNumber(thisMonthVisitsNumber);;
        //查询所有套餐名称 预约数量 占比
        List<HotSetmealVo> setmealVos = orderInfoService.selectHotSetmeal();
        dataVo.setHotSetmeal(setmealVos);

        return dataVo;
    }
}
